/* Classify rules into groups and check whether baseline was used */

label define ruleGroup 1 "#1 only" 2 "Some ECUs" 3 "Some Shares" 4 "All ECUs" 5 "All Shares"
label define baseline 0 "Rule does not include a baseline" 1 "Rule includes a baseline"
label define minimumOutcome 0 "No minimum guaranteed" 1 "Minimum # shares guaranteed by rule"

forvalues part = 1/2 {

	gen part`part'RuleGroup = .
	
	/* choose to invest only in company #1, or
	   choose to invest in a given number of companies, which is then set to 1
   */
	gen oneCompanyRule`part' = part`part'RuleWC==0 | (part`part'RuleWC==3 & part`part'RuleNC==1)
	
	/* choose to invest only in all companies, or
	   choose to invest in a given number of companies, which is then set equal to the number of companies
   */
	gen allCompaniesRule`part' = part`part'RuleWC==2 | (part`part'RuleWC==3 & part`part'RuleNC==numCompanies)

	/* Neither */
	gen someCompaniesRule`part' = !oneCompanyRule`part' & !allCompaniesRule`part'

	replace part`part'RuleGroup = 1 if oneCompanyRule`part'

	replace part`part'RuleGroup = 2 if someCompaniesRule`part' & part`part'RuleRBO==1

	replace part`part'RuleGroup = 3 if someCompaniesRule`part' & part`part'RuleRBO==0

	replace part`part'RuleGroup = 4 if allCompaniesRule`part' & part`part'RuleRBO==1

	replace part`part'RuleGroup = 5 if allCompaniesRule`part' & part`part'RuleRBO==0

	label var oneCompanyRule`part' "Part `part' rule allocates budget to one company"
	label var allCompaniesRule`part' "Part `part' rule allocates budget to all companies"
	label var someCompaniesRule`part' "Part `part' rule allocates budget to some companies"

	/* Choose to use a baseline and sets baseline to a positive number
	   Exclude rule with equal tokens to all companies as adding a baseline makes no difference
   */
	gen part`part'RuleBaseline = part`part'RuleBTO==1 & part`part'RuleBT>0 & !(part`part'RuleGroup==5)

	/* This excludes equal number of ECUS with no baseline, as # shares may be arbitrarily
	low if the share price is high */
	gen part`part'RuleMinimum = (part`part'RuleGroup == 5) | part`part'RuleBaseline

	label var part`part'RuleGroup "Rule classification"
	label var part`part'RuleBaseline "Rule includes a non-zero baseline"
	label var part`part'RuleMinimum "Rule guarantees a given minimum payout"
	
	label values part`part'RuleGroup ruleGroup
	label values part`part'RuleBaseline baseline
	label values part`part'RuleMinimum minimumOutcome
	
	}
